package com.bigtotoro.shuiyincamera;

import android.annotation.TargetApi;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import com.bigtotoro.shuiyincamera.editimage.EditImageActivity;
import com.bigtotoro.shuiyincamera.editimage.utils.BitmapUtils;
import com.umeng.analytics.MobclickAgent;

import qiu.niorgai.StatusBarCompat;

//作品列表的视频预览
public class VideoDisplayActivity extends BaseActivity {
    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_display);
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.font_0));
        initBase();
        initView();
    }

    private int videoHeight, videoWidth, videoDuration;
    private void initView() {
        videoView = findViewById(R.id.video);

        Intent data = getIntent();
        if (data.getStringExtra("path")!=null){
            String videoPath = data.getStringExtra("path");

            videoView.setVideoURI(Uri.parse(videoPath));
            videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    videoWidth = mediaPlayer.getVideoWidth();
                    videoHeight = mediaPlayer.getVideoHeight();
                    videoDuration = mediaPlayer.getDuration();
                    Log.d("main", "setOnPreparedListener duration " + videoDuration);
                    videoView.start();
                    mediaPlayer.setLooping(true); //循环播放
                }
            });
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("VideoDisplayActivity");//统计页面
        MobclickAgent.onResume(this);
    }
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("VideoDisplayActivity");//统计页面
        MobclickAgent.onPause(this);
    }

}
